package com.bawei.system.remote.factory;

import com.bawei.common.core.domain.R;
import com.bawei.es.domain.IndexEntry;
import com.bawei.es.domain.IndexInfoResp;
import com.bawei.system.remote.api.RemoteEsDocsService;
import com.bawei.system.remote.api.RemoteEsIndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author : zhangyu
 * @date 2023/11/16 21:29
 *
 * Es索引熔断处理
 */
@Component
public class RemoteEsIndexFallbackFactory implements FallbackFactory<RemoteEsIndexService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteEsDocsFallbackFactory.class);
        @Override
    public RemoteEsIndexService create(Throwable cause) {
        // 日志记录
        log.info("文档操作失败:{}", cause.getMessage());
        // 创建新的RemoteEsIndexService实例
        return new RemoteEsIndexService() {
            @Override
            public R createIndex(IndexEntry indexEntry) {
                // 创建索引失败并返回失败结果
                return R.fail("创建索引失败" + cause.getMessage());
            }

            @Override
            public R deleteIndex(String indexName) {
                // 删除索引失败并返回失败结果
                return R.fail("删除索引失败" + cause.getMessage());
            }

            @Override
            public R isExists(String indexName) {
                // 查询索引失败并返回失败结果
                return R.fail("查询索引失败" + cause.getMessage());
            }

            @Override
            public R getIndex(String indexName) {
                // 获取索引信息失败并返回失败结果
                return R.fail("获取索引信息失败" + cause.getMessage());
            }

            @Override
            public R updateIndex(IndexEntry indexEntry) {
                // 修改索引失败并返回失败结果
                return R.fail("修改索引失败" + cause.getMessage());
            }
        };
    }

}
